package com.olympus.hermes.common.config;

import com.olympus.hermes.common.id.SnowflakeIdWorker;
import lombok.Data;
import org.hibernate.id.IdentifierGenerator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Mickey
 * @since 2021/1/14
 */
@Data
@Configuration
@ConditionalOnClass(IdentifierGenerator.class)
@ConfigurationProperties(prefix = "winter.snow")
public class SnowflakeIdConfig {

    private long workerId = 0;

    private long datacenterId = 0;

    @Bean
    SnowflakeIdWorker snowflakeIdWorker() {
        return new SnowflakeIdWorker(workerId, datacenterId);
    }
}
